#pragma once

#include <sstream>
#include <iostream>
#include "imglib/image.h"

namespace xml { class stream; }

namespace trm {

typedef img::image<unsigned char> grey_mask;
typedef std::stringstream encoding;

class compressed_grey_mask {
public:
	compressed_grey_mask() { }
	compressed_grey_mask(grey_mask const & m) { store(m); }
	bool empty() const { return code_.str().empty(); }
	void store(grey_mask const & m);
	void extract(grey_mask & m) const;
public:
	//reads or writes string with symbols 0-9A-F
	std::ostream & write_hex(std::ostream & out) const;
	std::istream & read_hex(std::istream & in);
	xml::stream & serialize(xml::stream & s);
private:
	mutable encoding code_; // in PNG format, mutable since even reading from stream requires its modification
};

//inlines

inline xml::stream & operator || (xml::stream & s, compressed_grey_mask & m)
	{ return m.serialize(s); }

} //namespace trm
